<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        var max = 20, //min,max是随机数范围[min,max]
            min = 1,
            arr = [],
            arr1 = [], //arr1是随机数里面每个数的相同次数集合的数组,从min~max;
            num = 0; //arr里面随机数相同的次数
        for (var i = 0; i < 5000; i++) { //这里i<5000,5000是随机数总数
            arr.push(Math.floor(Math.random() * (max - min + 1) + min))

        }
          for (var i = 0; i < arr.length; i++) {
              num = 0;
              for (var j = i; j < arr.length; j++) {
                  if (arr[i] === arr[j + 1] && arr[i] !== '') {
                      num++;
                      arr1[arr[i] - 1] = num;
                      arr[j + 1] = '';
                  }
              }
          }

        console.log(arr);
        console.log(arr1);
    </script>
</head>

<body>

</body>

</html>